<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>

        <ui:composition template="./../Template/generalTemplate.xhtml">


            <ui:define name="content">
                <h:form id="form">
                    <p:panel id="msgInbox" header="System Message Inbox" style="height:495px;">
                        <div style="margin-top:20px;margin-left:70px;margin-right:70px;margin-bottom:20px;"> 
                            <p:dataTable id="systemMsg" dynamic="true" emptyMessage="No Message in your box" value="#{msgInboxManagedBean.getSystemMessages()}" var ="messages" paginator="true" rows="7">

                                <p:column>
                                    <f:facet name="header">Title</f:facet>
                                    #{messages.title}
                                </p:column>
                                
                                <p:column>
                                    <f:facet name="header">Type</f:facet>
                                    #{messages.type}
                                </p:column>

                                <p:column>
                                    <f:facet name="header">From</f:facet>
                                    #{messages.senderName}
                                </p:column>

                                <p:column>
                                    <f:facet name="header">Sending Time</f:facet>
                                    #{messages.sendTime}
                                </p:column>
                                
                                <p:column style="font-weight:bold;">
                                    <f:facet name="header">Status</f:facet>
                                    #{messages.status}
                                </p:column>

                                <p:column style="width:70px;">
                                    <f:facet name="header">Action</f:facet>

                                    <p:commandButton action ="#{msgInboxManagedBean.viewSystemMsg(messages)}" image="ui-icon ui-icon-search" title="View" />  

                                    <p:commandButton update=":form:display" oncomplete="confirmation.show()" image="ui-icon ui-icon-close" title="Delete" >
                                        <f:setPropertyActionListener value="#{messages}" target="#{msgInboxManagedBean.selectedMessage}" />  
                                    </p:commandButton>

                                </p:column>


                            </p:dataTable>

                            <p:confirmDialog message="Are you sure to delete?" 
                                             showEffect="explode" hideEffect="explode"  
                                             header="Confirm" severity="alert" widgetVar="confirmation">  

                                <p:commandButton value="Confirm" update="systemMsg" actionListener="#{msgInboxManagedBean.deleteMsg}" oncomplete="confirmation.hide()">  
                                    <f:attribute name="deleteMsg" value="#{msgInboxManagedBean.selectedMessage.id}" />
                                </p:commandButton>
                                
                                <p:commandButton value="Cancel" onclick="confirmation.hide()" type="button" />  

                            </p:confirmDialog>
                        </div>
                    </p:panel>
                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>